﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Linq;

namespace LinearAlgebra
{
    public partial class VectorBasisChangeForm : Form
    {
        public VectorBasisChangeForm()
        {
            InitializeComponent();
        }
        private void FloatInput(object sender, KeyEventArgs e)
        {
            if (UtilityMethods.ValidateFloatKeyEvent((TextBox)sender, e))
                Close();
        }

        private void ConvertButton_Click(object sender, EventArgs e)
        {            
            float stdX = float.Parse(StdX.Text);
            float stdY = float.Parse(StdY.Text);

            float b1X = float.Parse(B1X.Text);
            float b1Y = float.Parse(B1Y.Text);

            float b2X = float.Parse(B2X.Text);
            float b2Y = float.Parse(B2Y.Text);

            float determinate = b1X * b2Y - b1Y * b2X;

            if(determinate == 0)
            {
                InvalidBasisDialog errorBox = new InvalidBasisDialog("The new basis");                
                errorBox.ShowDialog( );
                return;
            }

            VectorBasisChangeDialog dialog = new VectorBasisChangeDialog(stdX, stdY, b1X, b1Y, b2X, b2Y);
            dialog.ShowDialog( );
        }

        private void Back_Click(object sender, EventArgs e)
        {
            Close( );
        }
        private void Randomize_Click(object sender, EventArgs e)
        {
            RandomizeValues( );
        }
        private void RandomizeValues()
        {
            StdX.Text = UtilityMethods.GetRandomNumberString(20);
            StdY.Text = UtilityMethods.GetRandomNumberString(20);

            B1X.Text = UtilityMethods.GetRandomNumberString(20);
            B1Y.Text = UtilityMethods.GetRandomNumberString(20);

            B2X.Text = UtilityMethods.GetRandomNumberString(20);
            B2Y.Text = UtilityMethods.GetRandomNumberString(20);
        }
        

        private void VectorBasisChangeForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            SelectionForm form = new SelectionForm( );
            form.Location = this.Location;
            form.Show( );
        }     
    }
}
